<template>
  <div>
    <!-- 返利使用规则设定 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="qjhRebateRulesSet"
      :columns="columns"
      :isSelectColumn="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" @click="addHandle">新 增</el-button>
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="visible" :title="drawerTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList } from '@/api/omFinance/RebateManage/RebateRulesSet';
import SonModel from './SonModel';

export default {
  name: 'RebateRulesSet',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '详情' };
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {
        // optionCode: '',
        // optionName: '',
        // powerType: '',
        // rebateType: '',
        // status: '',
        // startDate: '',
        // endDate: ''
      },
      formData: {},
      visible: false,
      handleType: '',
      drawerTitle: ''
    };
  },
  components: {
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },
    addHandle() {
      this.handleType = 'add';
      this.formData = {};
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
      console.log(this.formData)
      this.showHandler();
    },
    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '请输入'
        },
        // {
        //   type: 'INPUT',
        //   label: '选装代码',
        //   fieldName: 'optionCode',
        //   placeholder: '请输入'
        // },
        // {
        //   type: 'INPUT',
        //   label: '选装名称',
        //   fieldName: 'optionName',
        //   placeholder: '请输入'
        // },
        {
          type: 'SELECT',
          label: '返利类型',
          fieldName: 'rebateType',
          placeholder: '请选择',
          itemList: this.createDictList('2412').filter(x=>x.value!==60361003)
        },
        {
          type: 'SELECT',
          label: '启用状态',
          fieldName: 'status',
          placeholder: '请选择',
          itemList: this.createDictList('1003')
        },
        {
          type: 'RANGE_DATE',
          label: '生效日期',
          fieldName: 'startDate|endDate',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
        // {
        //   type: 'SELECT',
        //   label: '动力形式',
        //   fieldName: 'powerType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('6008')
        // }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        // {
        //   title: '品牌',
        //   dataIndex: 'brandName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
          // title: '动力形式',
          // dataIndex: 'powerType',
          // sorter: true,
          // filter: true,
          // filterType: 'checkbox',
          // filterItems: this.createDictList('6008'),
          // render: props => {
          //   return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          // }
        // },
        {
          title: '返利类型',
          dataIndex: 'rebateType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2412'),
          render: props => {
            return <span>{this.createDictText(props.row.rebateType, '2412')}</span>;
          }
        },
        {
          title: '返利方式',
          dataIndex: 'rebateMethod',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2414'),
          render: props => {
            return <span>{this.createDictText(props.row.rebateMethod, '2414')}</span>;
          }
        },
        {
          title: '返利上限',
          dataIndex: 'rebateLimitAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1003'),
          render: props => {
            return <span>{this.createDictText(props.row.status, '1003')}</span>;
          }
        },
        {
          title: '生效日期',
          dataIndex: 'startDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '失效日期',
          dataIndex: 'endDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '经销商代码',
        //   dataIndex: 'dealerCode',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '经销商名称',
        //   dataIndex: 'dealerName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    }
  }
};
</script>
